#include "pch.h"
#include "seBackground.h"



seBackground::seBackground()
{

}

void seBackground::Load()
{
	mBackground[0].LoadFromFile("data/heartbgr1.png");
	mBackground[1].LoadFromFile("data/heartbgr2.png");
	mBackground[2].LoadFromFile("data/heartbgr3.png");
}

void seBackground::Unload()
{

}

void seBackground::Init()
{
	fCurrentAlpha = 0.0f;
	iCurrentImage = 0;

	mActiveSprite.SetImage(mBackground[ iCurrentImage ]);
	mActiveSprite.SetColor(sf::Color(255,255,255,255));
	mIncomingSprite.SetImage(mBackground[ ( iCurrentImage + 1 ) % 3]);
	mIncomingSprite.SetColor(sf::Color(255,255,255, fCurrentAlpha)); // na poczatku ustawiamy na przezroczyste

	mActiveSprite.SetPosition(viewWidth/2 - mBackground[0].GetWidth()/2 , 0);
	mIncomingSprite.SetPosition(viewWidth/2 - mBackground[0].GetWidth()/2 , 0);


}

void seBackground::Step()
{
	fCurrentAlpha += ONE_FRAME_DURATION * 100.0f;

	mIncomingSprite.SetColor(sf::Color(255,255,255, (int)fCurrentAlpha));

	if (fCurrentAlpha > 255.0f)
	{
		fCurrentAlpha = 0.0f; // ustawiamy na zero
		iCurrentImage = (iCurrentImage + 1) % 3; // nastepny z kolei obrazek bierzemy

		mActiveSprite.SetImage(mBackground[iCurrentImage]);
		mIncomingSprite.SetImage(mBackground[ (iCurrentImage + 1) % 3 ]);

		mIncomingSprite.SetColor(sf::Color(255,255,255,0)); // ustawiamy na calkowicie przezroczyste


	}
}

void seBackground::Draw()
{
	mActiveSprite.SetPosition(viewWidth/2 - mBackground[0].GetWidth()/2 , 0);
	mIncomingSprite.SetPosition(viewWidth/2 - mBackground[0].GetWidth()/2 , 0);
	app.Draw(mActiveSprite);
	app.Draw(mIncomingSprite);
}